package com.hr;

import java.util.Map;

import com.espirit.builder.biz.VoucherBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;

//@Component
public abstract class SalaryItemBaseBuilderSupport extends VoucherBuilderSupport {
	protected static final String EMPLOYEE = "employee";
	static final String DEPARTMENT = "department";
	static final String CREATED = "created";
	static final String SALARYACCT = "acct";
	static final String DEPTIDS = "deptIds";
	
	@Override
	public boolean init() {
		return super.setClass(SalaryItemBase.class, "Salary Item", "工资清单");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(EMPLOYEE, "Employee", "职员");
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(DEPTIDS, "Department", "部门");
		addModelField(CREATED, "Created", "创建");
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(EMPLOYEE, ACCTTERM, SALARYACCT, DEPTIDS, CREATEDON));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(EMPLOYEE, ACCTTERM, SALARYACCT, ACCTITEM, AMOUNT, DC, DEPARTMENT, CREATED, CREATEDON));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(EMPLOYEE, ACCTTERM, SALARYACCT, ACCTITEM, AMOUNT, DC));
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
			String name = element.getName();
			if (name.equals(SALARYACCT + ".id")){
				element.setI18n("工资项目");
			} 
			
			if (name.equals(SALARYACCT + ".id")){
				Map<String, String> exProperties = element.safeExProperties();
				exProperties.put("model", getAcctItemClassName());
				element.setExProperty(exProperties);
				element.setTagName("modelselect");
			}
			return element;
	}
	
	protected abstract String getAcctItemClassName();
	
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{EMPLOYEE, ACCTTERM, SALARYACCT, AMOUNT, DC});
	}
	
	
}
